package com.lap.framework.junit.shared.tool;

import java.util.stream.Stream;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

@UtilityClass
public final class UriUtil {

  private static final String SLASH = "/";

  public static String getUri(String... uris) {
    return SLASH
        + String.join(
            SLASH,
            Stream.of(uris)
                .filter(StringUtils::isNotBlank)
                .map(uri -> uri.startsWith(SLASH) ? uri.substring(1) : uri)
                .toArray(String[]::new));
  }

  public static String getFirstUri(String[] uris) {
    return ArrayUtils.isEmpty(uris)
        ? ""
        : Stream.of(uris).filter(StringUtils::isNotBlank).findFirst().orElse("");
  }
}
